package com.qf.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.qf.pojo.respVo.BaseResp;
import com.qf.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/course")
@RestController
public class CourseController {

    @Autowired
    CourseService courseService;

    /**
     * 通过分类id查询课程
     * @param id
     * @param page
     * @param size
     * @return
     */
    @RequestMapping("/findCourseByClassify/{id}/{page}/{size}")
    public BaseResp finCourseByClassify(@PathVariable("id")Integer id,@PathVariable("page")Integer page,@PathVariable("size")Integer size){
            return courseService.finCourseByClassify(id,page,size);
    }

    @RequestMapping("/findCourseDetailById/{id}")
    @HystrixCommand(fallbackMethod = "findCourseDetailByIdFallBack")
    public BaseResp findCourseDetailById(@PathVariable("id")Integer id){
            return courseService.findCourseDetailById(id);
    }

    public BaseResp findCourseDetailByIdFallBack(@PathVariable("id")Integer id){
        return new BaseResp(0,"网络不佳！",null,null);
    }
}
